﻿using System;

namespace GLDotNet
{
    public sealed class IndexBuffer<T> : BufferBase<T>
        where T : struct
    {
        protected override BufferTarget BufferTarget
        {
            get { return BufferTarget.ElementArrayBuffer; }
        }

        public DrawElementsType DrawElementType
        {
            get;
            private set;
        }

        public IndexBuffer(GraphicsDevice context)
            : base(context)
        {
            Type dataType = typeof(T);

            if (dataType == typeof(byte))
            {
                this.DrawElementType = DrawElementsType.UnsignedByte;
            }
            else if (dataType == typeof(ushort))
            {
                this.DrawElementType = DrawElementsType.UnsignedShort;
            }
            else if (dataType == typeof(uint))
            {
                this.DrawElementType = DrawElementsType.UnsignedInt;
            }
            else
            {
                throw new InvalidOperationException("IndexBuffer may only have a data type of byte, ushort, or uint.");
            }

            this.Handle = this.GenerateBuffer();
        }
    }
}
